<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!--onsubmit="return validateCallback(this)"-->
                        <form class="form-horizontal" action="{:U('update')}"  method="post"  id="form-purch" onsubmit="return validateCallback(this)">

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 批次名要求唯一 </label>
                                <div class="col-sm-9">
                                    <empty>
                                    <{if condition="!$goods.poname" }> onblur="checkponame(this)" <{/if}> 
                                    <input type="text" name="arr[poname]"  id="poname" class="rcol-xs-10 col-sm-5" value="{$goods.poname}"onblur="checkponame(this)">
                                </div>

                            </div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 描述 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[desc]" id="desc" datatype="*" nullmsg="描述不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.desc}" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 供应商 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[supplier]" id="supplier" datatype="*" nullmsg="供应商不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.supplier}" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>


                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-10"> 贸易模式 </label>
                                <div class="col-sm-9">

                                    <select id="trade_type" name="arr[trade_type]" class="rcol-xs-10 col-sm-5">
                                        <volist name="tradeList" id="val">
                                            <option value="{$val['code']}"
                                        <if condition="$val['code'] eq $goods['trade_type']">selected="selected"
                                        </if>
                                        >{$val['code']}--{$val['name']}</option>
                                    </volist>
                                </select>

                            </div>
                        </div>
                        <div class="space-4"></div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label no-padding-right" for="form-field-10"> 原产国 </label>
                            <div class="col-sm-9">

                                <select id="courty" name="arr[courty]" class="rcol-xs-10 col-sm-5">
                                    <option value="">请选择原产国</option>
                                    <volist name="country" id="val">
                                        <option value="{$val['code']}"
                                    <if condition="$val['code'] eq $goods['courty']">selected="selected"
                                    </if>
                                    >{$val['code']}--{$val['chinese_name']}</option>
                                </volist>
                            </select>

                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="id-date-picker-1">订单时间</label>
                        <div class="col-xs-9 col-sm-9">
                            <div class="input-group col-xs-5">
                                <input class="form-control"  id="ptime" name="arr[ptime]" value="<if condition="
                                       $goods['ptime'] neq '' ">{$goods['ptime']|date="Y-m-d",###}</if>"
                                type="text" data-date-format="dd-mm-yyyy" />
                                <span class="input-group-addon">
                                    <i class="ace-icon fa fa-calendar bigger-110"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> untax_amount不含税价 </label>
                        <div class="col-sm-9">
                            <input type="text" name="arr[untax_amount]" id="untax_amount" datatype="*" nullmsg="untax_amount不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.untax_amount}" autocomplete="off" data-bv-notempty />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> amount金额 </label>
                        <div class="col-sm-9">
                            <input type="text" name="arr[amount]" id="amount" datatype="*" nullmsg="amount不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.amount}" autocomplete="off" data-bv-notempty />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 币种curr </label>
                        <div class="col-sm-9">
                            <input type="text" name="arr[curr]" id="curr" datatype="*" nullmsg="curr不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.curr?$goods.curr:'CNY'}" autocomplete="off" data-bv-notempty />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 汇率(price/curr_rate) </label>
                        <div class="col-sm-9">
                            <input type="text" name="arr[curr_rate]" id="curr_rate" datatype="*" nullmsg="curr_rate不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.curr_rate}" autocomplete="off" data-bv-notempty />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 业务状态 </label>
                        <div class="col-sm-9">
                            <input type="text" name="arr[state]" id="state" datatype="*" nullmsg="state不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.state}" autocomplete="off" data-bv-notempty />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> from_flagerp\\zt\\采购单来源 </label>
                        <div class="col-sm-9">
                            <input type="text" name="arr[from_flag]" id="flag" datatype="*" nullmsg="erp\\zt\\采购单来源不能为空" class="rcol-xs-10 col-sm-5" value="zt" autocomplete="off" data-bv-notempty />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1">采购企业 </label>
                        <div class="col-sm-9">
                            <input type="text" name="arr[compay]" id="compay" datatype="*" nullmsg="compay不能为空" class="rcol-xs-10 col-sm-5" value="{$goods.compay}" autocomplete="off" data-bv-notempty />
                        </div>
                    </div>
                    <style>
                        .purch-div{border-bottom: 1px solid #006dcc;}
                    </style>


                    <div class="space-4"></div>
                    <div class="space-4"></div>

                    <div class="purch-p-div" style="border:1px solid #AAAADD;padding: 5px;">
                        <div class="purch-div" purch-id="0">
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">商品sku </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[line][sku][]" datatype="*" nullmsg="商品sku不能为空" onblur="getskuinfo(this);" class="rcol-xs-10 col-sm-5" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">商品名称 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[line][name][]"  datatype="*" nullmsg="商品名称不能为空" class="rcol-xs-10 col-sm-5" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">列表价格 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[line][lstprice][]"  datatype="*" nullmsg="列表价格不能为空" class="rcol-xs-10 col-sm-5" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">本币价格 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[line][locprice][]"  datatype="*" nullmsg="本币价格不能为空" class="rcol-xs-10 col-sm-5" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">earn13码 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[line][earn13][]"  datatype="*" nullmsg="earn13不能为空" class="rcol-xs-10 col-sm-5" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">数量 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="arr[line][num][]"  datatype="*" nullmsg="数量不能为空" class="rcol-xs-10 col-sm-5" autocomplete="off" data-bv-notempty />
                                </div>
                            </div>

                            <a class="btn" href="javascript:void(0)" onclick="addnewpurch(this)">添加</a>
                            <a class="btn" href="javascript:void(0)" onclick="removepurch(this)">删除</a>

                        </div>




                    </div>


                    <div class="space-4"></div>
                    <div class="col-md-offset-2 col-md-9">
                        <button class="btn btn-info" type="submit">
                            <i class="icon-ok bigger-110"></i>
                            提交
                        </button>

                        &nbsp; &nbsp; &nbsp;
                        <button class="btn" type="reset">
                            <i class="icon-undo bigger-110"></i>
                            重置
                        </button>
                    </div>
                </form>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
</div>
</div><!-- /.main-content -->
<include file="Public/footer"/>

</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<!-- inline scripts related to this page -->
<script src="__PUBLIC__/qwadmin/js/date-time/bootstrap-datepicker.js"></script>
<script src="__PUBLIC__/qwadmin/js/function.js"></script>
<script type="text/javascript">


                                function getskuinfo(obj) {
                                    var name = $(obj).val();
                                    var objparent = $(obj).parent().parent().parent();
                                    $(".Validform_wrong").remove();
                                    if (name) {
                                        $.post("{:U('getskuinfo')}", {"sku": name}, function (data) {
                                            if (data.status == 1) {
                                                $(objparent).find("input[name='arr[line][name][]']").val(data.data.name);
                                                $(objparent).find("input[name='arr[line][earn13][]']").val(data.data.earn13);
                                            }

                                        });
                                    }


                                }

                                function addnewpurch(obj) {
                                    $(obj).parent().clone().appendTo(".purch-p-div");
                                }
                                function removepurch(obj) {
                                    $(obj).parent().remove();
                                }

                                jQuery(function ($) {
                                    $('#ptime').datepicker({
                                        format: 'yyyy-mm-dd',
                                        weekStart: 1,
                                        autoclose: true,
                                        todayBtn: 'linked',
                                        language: 'cn'
                                    });
//                                        $('#form-purch').submit(function(){
//                                            
//                                            alert(111);
//                                var flag = 1;
//                                        var msg = "";
//                                        if (!$("#poname").val()){
//                                msg += "批次名称为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#supplier").val()){
//                                msg += "供应商为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#trade_type").val()){
//                                msg += "贸易模式为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#courty").val()){
//                                msg += "原产国为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#ptime").val()){
//                                msg += "采购时间为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#untax_amount").val()){
//                                msg += "untax_amount为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#amount").val()){
//                                msg += "amount为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#curr").val()){
//                                msg += "curr为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#curr_rate").val()){
//                                msg += "curr_rate为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$("#state").val()){
//                                msg += "state为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$('input[name="arr[line][sku][]"]').val()){
//                                msg += "SUK为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$('input[name="arr[line][name][]"]').val()){
//                                msg += "商品名为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$('input[name="arr[line][lstprice][]"]').val()){
//                                msg += "lstprice为空\r\n";
//                                        flag = 0;
//                                }
//                                if (!$('input[name="arr[line][locprice][]"]').val()){
//                                msg += "locprice为空\r\n";
//                                        flag = 0;
//                                }
//
//                                if (flag === 0){
//                                    alert(msg);
//                                      return;
//                                }else{
//                                    $(this).submit();
//                                }
//                                return ;
//                                });

                                });
                                function checkponame(obj) {
                                    var name = $(obj).val();
                                    if (name) {
                                        $(".Validform_wrong").remove();
                                        $.post("{:U('checkpo')}", {"name": name}, function (data) {
                                            if (data.status == 0) {
                                                $(obj).after('<span class="Validform_checktip Validform_wrong ">' + data.msg + '</span>');
                                            }

                                        });
                                    } else {
                                        $(obj).after('<span class="Validform_checktip Validform_wrong ">批次名不允许为空</span>');
                                    }
                                }

                                function validateCallback(obj) {
                                    var flag = 1;
                                    var msg = "";
                                    if (!$("#poname").val()) {
                                        msg += "批次名称为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#supplier").val()) {
                                        msg += "供应商为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#trade_type").val()) {
                                        msg += "贸易模式为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#courty").val()) {
                                        msg += "原产国为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#ptime").val()) {
                                        msg += "采购时间为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#untax_amount").val()) {
                                        msg += "untax_amount为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#amount").val()) {
                                        msg += "amount为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#curr").val()) {
                                        msg += "curr为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#curr_rate").val()) {
                                        msg += "curr_rate为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$("#state").val()) {
                                        msg += "state为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$('input[name="arr[line][sku][]"]').val()) {
                                        msg += "SUK为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$('input[name="arr[line][name][]"]').val()) {
                                        msg += "商品名为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$('input[name="arr[line][lstprice][]"]').val()) {
                                        msg += "lstprice为空\r\n";
                                        flag = 0;
                                    }
                                    if (!$('input[name="arr[line][locprice][]"]').val()) {
                                        msg += "locprice为空\r\n";
                                        flag = 0;
                                    }

                                    if (flag === 0) {
                                        alert(msg);
                                        return false;
                                    }
                                    $(obj).submit();
                                }

</script>

</body>
</html>
